package com.gdth.bank.ui;

import java.util.List;

import com.gdth.bank.R;
import com.gdth.bank.adapter.ContactListAdapter;
import com.gdth.bank.bean.ContactBean;
import com.gdth.bank.presenter.ContactPresenter;
import com.gdth.bank.view.ContactView;
import com.gdth.core.annotation.view.ViewInject;
import com.gdth.core.widget.BaseFrameLayout;
import com.gdth.widget.dialog.BaseToast;

import android.app.Activity;
import android.content.Context;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

public class ContactListFragment extends BaseFrameLayout implements ContactView{
	
	/****/
	@ViewInject(id=R.id.contact_list, itemClick="onItemClick") ListView contactList;
	/**快速索引条**/
	@ViewInject(id=R.id.fast_scroller) QuickAlphabeticBar alphabeticBar;

	ContactPresenter mContactPresenter;
	
	private ContactListAdapter adapter;
	
	private List<ContactBean> contactBeans;
	
	public ContactListFragment(Context context){
		super(context, R.layout.contact_list_layout);
	}
	
	@Override
	public void initializeView(){
		
	}
	
	@Override
	public void initializePresenter(){
		mContactPresenter = new ContactPresenter(this);
		
		mContactPresenter.getContactList();
	}
	
	private void setAdapter(List<ContactBean> list) {
		adapter = new ContactListAdapter(this.context, list, alphabeticBar);
		contactList.setAdapter(adapter);
		alphabeticBar.init((Activity)context);
		alphabeticBar.setListView(contactList);
		alphabeticBar.setHight(alphabeticBar.getHeight());
		alphabeticBar.setVisibility(View.VISIBLE);
	}
	
	public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
		ContactBean mContactBean = contactBeans.get(arg2);
		
		String number = mContactBean.getPhoneNum();
		showMessage("你选择了号码：" + number);
		//用intent启动拨打电话  
//		Intent intent = new Intent(Intent.ACTION_CALL,Uri.parse("tel:"+number));  
//		startActivity(intent);  
	}

	@Override
	public void updateContacts(List<ContactBean> contactList){
		// TODO Auto-generated method stub
		contactBeans = contactList;
		setAdapter(contactList);
	}

	@Override
	public void showProgressDialog() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void hideProgressDialog() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void showMessage(String msg) {
		// TODO Auto-generated method stub
		BaseToast.getInstance().ShowSystemToast(context, msg);
	}
}
